home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / hobby / ast44src.zip / XCHARTS2.C < prev    next >
C/C++ Source or Header  |  1995-02-11  |  20KB  |  539 lines

  1. /*
  2. ** Astrolog (Version 4.40) File: xcharts2.c
  3. **
  4. ** IMPORTANT NOTICE: The graphics database and chart display routines
  5. ** used in this program are Copyright (C) 1991-1995 by Walter D. Pullen
  6. ** (astara@u.washington.edu). Permission is granted to freely use and
  7. ** distribute these routines provided one doesn't sell, restrict, or
  8. ** profit from them in any way. Modification is allowed provided these
  9. ** notices remain with any altered or edited versions of the program.
  10. **
  11. ** The main planetary calculation routines used in this program have
  12. ** been Copyrighted and the core of this program is basically a
  13. ** conversion to C of the routines created by James Neely as listed in
  14. ** Michael Erlewine's 'Manual of Computer Programming for Astrologers',
  15. ** available from Matrix Software. The copyright gives us permission to
  16. ** use the routines for personal use but not to sell them or profit from
  17. ** them in any way.
  18. **
  19. ** The PostScript code within the core graphics routines are programmed
  20. ** and Copyright (C) 1992-1993 by Brian D. Willoughby
  21. ** (brianw@sounds.wa.com). Conditions are identical to those above.
  22. **
  23. ** The extended accurate ephemeris databases and formulas are from the
  24. ** calculation routines in the program "Placalc" and are programmed and
  25. ** Copyright (C) 1989,1991,1993 by Astrodienst AG and Alois Treindl
  26. ** (alois@azur.ch). The use of that source code is subject to
  27. ** regulations made by Astrodienst Zurich, and the code is not in the
  28. ** public domain. This copyright notice must not be changed or removed
  29. ** by any user of this program.
  30. **
  31. ** Initial programming 8/28,30, 9/10,13,16,20,23, 10/3,6,7, 11/7,10,21/1991.
  32. ** X Window graphics initially programmed 10/23-29/1991.
  33. ** PostScript graphics initially programmed 11/29-30/1992.
  34. ** Last code change made 1/29/1995.
  35. */
  36.  
  37. #include "astrolog.h"
  38.  
  39.  
  40. #ifdef GRAPH
  41. /*
  42. ******************************************************************************
  43. ** Chart Graphics Utility Procedures.
  44. ******************************************************************************
  45. */
  46.  
  47. /* Return whether the specified object should be displayed in the current */
  48. /* graphics chart type. For example, don't include the Moon in the solar  */
  49. /* system charts, don't include house cusps in astro-graph, and so on.    */
  50.  
  51. bool FProper(i)
  52. int i;
  53. {
  54.   bool f;
  55.  
  56.   if (gi.nMode == gHorizon || gi.nMode == gEphemeris || fMap ||
  57.     gi.nMode == gGlobe || gi.nMode == gPolar) /* Astro-graph / ephem charts */
  58.     f = FObject(i);
  59.   else if (gi.nMode == gOrbit)                /* Solar system charts */
  60.     f = FObject(i) && (i != oMoo || (us.fPlacalc && us.objCenter < oMoo));
  61.   else
  62.     f = fTrue;
  63.   return f && !ignore[i];                     /* Check restriction status */
  64. }
  65.  
  66.  
  67. /* Adjust an array of zodiac positions so that no two positions are within   */
  68. /* a certain orb of each other. This is used by the wheel drawing chart      */
  69. /* routines in order to make sure that we don't draw any planet glyphs on    */
  70. /* top of each other. We'll later draw the glyphs at the adjusted positions. */
  71.  
  72. void FillSymbolRing(symbol)
  73. real *symbol;
  74. {
  75.   real orb = DEFORB*256.0/(real)gs.yWin*(real)gi.nScale, k1, k2, temp;
  76.   int i, j, k = 1, l;
  77.  
  78.   /* Keep adjusting as long as we can still make changes, or until we do 'n' */
  79.   /* rounds. (With many objects, there just may not be enough room for all.) */
  80.  
  81.   for (l = 0; k && l < us.nDivision*2; l++) {
  82.     k = 0;
  83.     for (i = 1; i <= cObj; i++) if (FProper(i)) {
  84.  
  85.       /* For each object, determine who is closest on either side. */
  86.  
  87.       k1 = rLarge; k2 = -rLarge;
  88.       for (j = 1; j <= cObj; j++)
  89.         if (FProper(j) && i != j) {
  90.           temp = symbol[j]-symbol[i];
  91.           if (RAbs(temp) > rDegHalf)
  92.             temp -= rDegMax*RSgn(temp);
  93.           if (temp < k1 && temp >= 0.0)
  94.             k1 = temp;
  95.           else if (temp > k2 && temp <= 0.0)
  96.             k2 = temp;
  97.         }
  98.  
  99.       /* If an object's too close on one side, then we move to the other. */
  100.  
  101.       if (k2 > -orb && k1 > orb) {
  102.         k = 1; symbol[i] = Mod(symbol[i]+orb*0.51+k2*0.49);
  103.       } else if (k1 < orb && k2 < -orb) {
  104.         k = 1; symbol[i] = Mod(symbol[i]-orb*0.51+k1*0.49);
  105.  
  106.       /* If we are bracketed by close objects on both sides, then let's move */
  107.       /* to the midpoint, so we are as far away as possible from either one. */
  108.  
  109.       } else if (k2 > -orb && k1 < orb) {
  110.         k = 1; symbol[i] = Mod(symbol[i]+(k1+k2)*0.5);
  111.       }
  112.     }
  113.   }
  114. }
  115.  
  116.  
  117. /* Adjust an array of longitude positions so that no two are within a    */
  118. /* certain orb of each other. This is used by the astro-graph routine to */
  119. /* make sure we don't draw any planet glyphs marking the lines on top of */
  120. /* each other. This is almost identical to the FillSymbolRing() routine  */
  121. /* used by the wheel charts; however, there the glyphs are placed in a   */
  122. /* continuous ring, while here we have the left and right screen edges.  */
  123. /* Also, here we are placing two sets of planets at the same time.       */
  124.  
  125. void FillSymbolLine(symbol)
  126. real *symbol;
  127. {
  128.   real orb = DEFORB*1.35*(real)gi.nScale, max = rDegMax, k1, k2, temp;
  129.   int i, j, k = 1, l;
  130.  
  131.   if (gi.nMode != gEphemeris)
  132.     max *= (real)gi.nScale;
  133.   else
  134.     orb *= rDegMax/(real)gs.xWin;
  135.  
  136.   /* Keep adjusting as long as we can still make changes. */
  137.  
  138.   for (l = 0; k && l < us.nDivision*2; l++) {
  139.     k = 0;
  140.     for (i = 1; i <= cObj*2; i++)
  141.       if (FProper((i+1)/2) && symbol[i] >= 0.0) {
  142.  
  143.         /* For each object, determine who is closest to the left and right. */
  144.  
  145.         k1 = max-symbol[i]; k2 = -symbol[i];
  146.         for (j = 1; j <= cObj*2; j++) {
  147.           if (FProper((j+1)/2) && i != j) {
  148.             temp = symbol[j]-symbol[i];
  149.             if (temp < k1 && temp >= 0.0)
  150.               k1 = temp;
  151.             else if (temp > k2 && temp <= 0.0)
  152.               k2 = temp;
  153.           }
  154.         }
  155.  
  156.         /* If an object's too close on one side, then we move to the other. */
  157.  
  158.         if (k2 > -orb && k1 > orb) {
  159.           k = 1; symbol[i] = symbol[i]+orb*0.51+k2*0.49;
  160.         } else if (k1 < orb && k2 < -orb) {
  161.           k = 1; symbol[i] = symbol[i]-orb*0.51+k1*0.49;
  162.         } else if (k2 > -orb && k1 < orb) {
  163.           k = 1; symbol[i] = symbol[i]+(k1+k2)*0.5;
  164.         }
  165.       }
  166.   }
  167. }
  168.  
  169.  
  170. /* Given a zodiac degree, adjust it if need be to account for the expanding */
  171. /* and compacting of parts the zodiac that happen when we display a graphic */
  172. /* wheel chart such that all the houses appear the same size.               */
  173.  
  174. real HousePlaceInX(deg)
  175. real deg;
  176. {
  177.   int in;
  178.  
  179.   if (gi.nMode == gWheel)    /* We only adjust for the -w -X combination. */
  180.     return deg;
  181.   in = HousePlaceIn(deg);
  182.   return Mod(ZFromS(in)+MinDistance(house[in], deg)/
  183.     MinDistance(house[in], house[Mod12(in+1)])*30.0);
  184. }
  185.  
  186.  
  187. /*
  188. ******************************************************************************
  189. ** Multiple Chart Graphics Routines.
  190. ******************************************************************************
  191. */
  192.  
  193. /* Draw another wheel chart; however, this time we have two rings of planets */
  194. /* because we are doing a relationship chart between two sets of data. This  */
  195. /* chart is obtained when the -r0 is combined with the -X switch.            */
  196.  
  197. void XChartWheelRelation()
  198. {
  199.   real xsign[cSign+1], xhouse1[cSign+1], xplanet1[objMax], xplanet2[objMax],
  200.     symbol[objMax];
  201.   int cx, cy, i, j;
  202.   real asc, unitx, unity, px, py, temp;
  203.  
  204.   /* Set up variables and temporarily automatically decrease the horizontal */
  205.   /* chart size to leave room for the sidebar if that mode is in effect.    */
  206.  
  207.   if (gs.fText && !us.fVelocity)
  208.     gs.xWin -= xSideT;
  209.   cx = gs.xWin/2 - 1; cy = gs.yWin/2 - 1;
  210.   unitx = (real)cx; unity = (real)cy;
  211.   asc = gs.nLeft ? cp1.obj[abs(gs.nLeft)]+90*(gs.nLeft < 0) : cp1.cusp[1];
  212.  
  213.   /* Fill out arrays with the degree of each object, cusp, and sign glyph. */
  214.  
  215.   if (gi.nMode == gWheel) {
  216.     for (i = 1; i <= cSign; i++)
  217.       xhouse1[i] = PZ(cp1.cusp[i]);
  218.   } else {
  219.     asc -= cp1.cusp[1];
  220.     for (i = 1; i <= cSign; i++)
  221.       xhouse1[i] = PZ(ZFromS(i));
  222.   }
  223.   for (i = 1; i <= cSign; i++)
  224.     xsign[i] = PZ(HousePlaceInX(ZFromS(i)));
  225.   for (i = 1; i <= cObj; i++)
  226.     xplanet1[i] = PZ(HousePlaceInX(cp1.obj[i]));
  227.   for (i = 1; i <= cObj; i++)
  228.     xplanet2[i] = PZ(HousePlaceInX(cp2.obj[i]));
  229.  
  230.   /* Draw the horizon and meridian lines across whole chart, and draw the */
  231.   /* zodiac and house rings, exactly like before. We are drawing only the */
  232.   /* houses of one of the two charts in the relationship, however.        */
  233.  
  234.   DrawColor(gi.kiLite);
  235.   DrawDash(cx+POINT1(unitx, 0.99, PX(xhouse1[sAri])),
  236.            cy+POINT1(unity, 0.99, PY(xhouse1[sAri])),
  237.            cx+POINT1(unitx, 0.99, PX(xhouse1[sLib])),
  238.            cy+POINT1(unity, 0.99, PY(xhouse1[sLib])), !gs.fColor);
  239.   DrawDash(cx+POINT1(unitx, 0.99, PX(xhouse1[sCap])),
  240.            cy+POINT1(unity, 0.99, PY(xhouse1[sCap])),
  241.            cx+POINT1(unitx, 0.99, PX(xhouse1[sCan])),
  242.            cy+POINT1(unity, 0.99, PY(xhouse1[sCan])), !gs.fColor);
  243.   for (i = 0; i < nDegMax; i += 5-(gs.fColor || gs.fPS || gs.fMeta)*4) {
  244.     temp = PZ(HousePlaceInX((real)i));
  245.     px = PX(temp); py = PY(temp);
  246.     DrawColor(i%5 ? gi.kiGray : gi.kiOn);
  247.     DrawDash(cx+POINT1(unitx, 0.78, px), cy+POINT1(unity, 0.78, py),
  248.       cx+POINT2(unitx, 0.82, px), cy+POINT2(unity, 0.82, py),
  249.       ((gs.fPS || gs.fMeta) && i%5)*2);
  250.   }
  251.  
  252.   DrawColor(gi.kiOn);
  253.   DrawCircle(cx, cy, (int)(unitx*0.95+rRound), (int)(unity*0.95+rRound));
  254.   DrawCircle(cx, cy, (int)(unitx*0.82+rRound), (int)(unity*0.82+rRound));
  255.   DrawCircle(cx, cy, (int)(unitx*0.78+rRound), (int)(unity*0.78+rRound));
  256.   DrawCircle(cx, cy, (int)(unitx*0.70+rRound), (int)(unity*0.70+rRound));
  257.  
  258.   for (i = 1; i <= cSign; i++) {
  259.     temp = xsign[i];
  260.     DrawColor(gi.kiOn);
  261.     DrawLine(cx+POINT2(unitx, 0.95, PX(temp)),
  262.       cy+POINT2(unity, 0.95, PY(temp)),
  263.       cx+POINT1(unitx, 0.82, PX(temp)),
  264.       cy+POINT1(unity, 0.82, PY(temp)));
  265.     DrawLine(cx+POINT2(unitx, 0.78, PX(xhouse1[i])),
  266.       cy+POINT2(unity, 0.78, PY(xhouse1[i])),
  267.       cx+POINT1(unitx, 0.70, PX(xhouse1[i])),
  268.       cy+POINT1(unity, 0.70, PY(xhouse1[i])));
  269.     if (gs.fColor && i%3 != 1) {
  270.       DrawColor(gi.kiGray);
  271.       DrawDash(cx, cy, cx+POINT1(unitx, 0.70, PX(xhouse1[i])),
  272.         cy+POINT1(unity, 0.70, PY(xhouse1[i])), 1);
  273.     }
  274.     temp = Midpoint(temp, xsign[Mod12(i+1)]);
  275.     DrawColor(kSignB(i));
  276.     DrawSign(i, cx+POINT1(unitx, 0.885, PX(temp)),
  277.       cy+POINT1(unity, 0.885, PY(temp)));
  278.     temp = Midpoint(xhouse1[i], xhouse1[Mod12(i+1)]);
  279.     DrawHouse(i, cx+POINT1(unitx, 0.74, PX(temp)),
  280.       cy+POINT1(unity, 0.74, PY(temp)));
  281.   }
  282.  
  283.   /* Draw the outer ring of planets (based on the planets in the chart     */
  284.   /* which the houses do not reflect - the houses belong to the inner ring */
  285.   /* below). Draw each glyph, a line from it to its actual position point  */
  286.   /* in the outer ring, and then draw another line from this point to a    */
  287.   /* another dot at the same position in the inner ring as well.           */
  288.  
  289.   for (i = 1; i <= cObj; i++)
  290.     symbol[i] = xplanet2[i];
  291.   FillSymbolRing(symbol);
  292.   for (i = cObj; i >= 1; i--) if (FProper2(i)) {
  293.     if (gs.fLabel) {
  294.       temp = symbol[i];
  295.       DrawColor(cp2.dir[i] < 0.0 ? gi.kiGray : gi.kiOn);
  296.       DrawDash(cx+POINT1(unitx, 0.58, PX(xplanet2[i])),
  297.         cy+POINT1(unity, 0.58, PY(xplanet2[i])),
  298.         cx+POINT2(unitx, 0.61, PX(temp)),
  299.         cy+POINT2(unity, 0.61, PY(temp)),
  300.         (cp2.dir[i] < 0.0 ? 1 : 0) - gs.fColor);
  301.       DrawObject(i, cx+POINT1(unitx, 0.65, PX(temp)),
  302.         cy+POINT1(unity, 0.65, PY(temp)));
  303.     }
  304.     DrawColor(kObjB[i]);
  305.     DrawPoint(cx+POINT1(unitx, 0.56, PX(xplanet2[i])),
  306.       cy+POINT1(unity, 0.56, PY(xplanet2[i])));
  307.     DrawPoint(cx+POINT1(unitx, 0.43, PX(xplanet2[i])),
  308.       cy+POINT1(unity, 0.43, PY(xplanet2[i])));
  309.     DrawColor(cp2.dir[i] < 0.0 ? gi.kiGray : gi.kiOn);
  310.     DrawDash(cx+POINT1(unitx, 0.45, PX(xplanet2[i])),
  311.       cy+POINT1(unity, 0.45, PY(xplanet2[i])),
  312.       cx+POINT2(unitx, 0.54, PX(xplanet2[i])),
  313.       cy+POINT2(unity, 0.54, PY(xplanet2[i])), 2-gs.fColor);
  314.   }
  315.  
  316.   /* Now draw the inner ring of planets. If it weren't for the outer ring,  */
  317.   /* this would be just like the standard non-relationship wheel chart with */
  318.   /* only one set of planets. Again, draw glyph, and a line to true point.  */
  319.  
  320.   for (i = 1; i <= cObj; i++)
  321.     symbol[i] = xplanet1[i];
  322.   FillSymbolRing(symbol);
  323.   for (i = 1; i <= cObj; i++) if (FProper(i)) {
  324.     if (gs.fLabel) {
  325.       temp = symbol[i];
  326.       DrawColor(cp1.dir[i] < 0.0 ? gi.kiGray : gi.kiOn);
  327.       DrawDash(cx+POINT1(unitx, 0.45, PX(xplanet1[i])),
  328.         cy+POINT1(unity, 0.45, PY(xplanet1[i])),
  329.         cx+POINT2(unitx, 0.48, PX(temp)),
  330.         cy+POINT2(unity, 0.48, PY(temp)),
  331.         (cp1.dir[i] < 0.0 ? 1 : 0) - gs.fColor);
  332.       DrawObject(i, cx+POINT1(unitx, 0.52, PX(temp)),
  333.         cy+POINT1(unity, 0.52, PY(temp)));
  334.     } else
  335.       DrawColor(kObjB[i]);
  336.     DrawPoint(cx+POINT1(unitx, 0.43, PX(xplanet1[i])),
  337.       cy+POINT1(unity, 0.43, PY(xplanet1[i])));
  338.   }
  339.  
  340.   /* Draw lines connecting planets between the two charts that have aspects. */
  341.  
  342.   if (!gs.fAlt) {                      /* Don't draw aspects in bonus mode. */
  343.     if (!FCreateGridRelation(fFalse))
  344.       return;
  345.     for (j = cObj; j >= 1; j--)
  346.       for (i = cObj; i >= 1; i--)
  347.         if (grid->n[i][j] && FProper2(i) && FProper(j)) {
  348.           DrawColor(kAspB[grid->n[i][j]]);
  349.           DrawDash(cx+POINT1(unitx, 0.41, PX(xplanet1[j])),
  350.             cy+POINT1(unity, 0.41, PY(xplanet1[j])),
  351.             cx+POINT1(unitx, 0.41, PX(xplanet2[i])),
  352.             cy+POINT1(unity, 0.41, PY(xplanet2[i])),
  353.             abs(grid->v[i][j]/60/2));
  354.         }
  355.   }
  356.  
  357.   /* Go draw sidebar with chart information and positions if need be. */
  358.  
  359.   DrawInfo();
  360. }
  361.  
  362.  
  363. /* Draw an aspect (or midpoint) grid in the window, between the planets in  */
  364. /* two different charts, with the planets labeled at the top and side. This */
  365. /* chart is done when the -g switch is combined with the -r0 and -X switch. */
  366. /* Like above, the chart always has a (definable) fixed number of cells.    */
  367.  
  368. void XChartGridRelation()
  369. {
  370.   char sz[cchSzDef];
  371.   int unit, siz, x, y, i, j, k, l;
  372.   KI c;
  373.  
  374.   unit = CELLSIZE*gi.nScale; siz = (gs.nGridCell+1)*unit;
  375.   if (!FCreateGridRelation(gs.fAlt != us.fGridConfig))
  376.     return;
  377.   for (y = 0, j = -1; y <= gs.nGridCell; y++) {
  378.     do {
  379.       j++;
  380.     } while (ignore[j] && j <= cObj);
  381.     DrawColor(gi.kiGray);
  382.     DrawDash(0, (y+1)*unit, siz, (y+1)*unit, !gs.fColor);
  383.     DrawDash((y+1)*unit, 0, (y+1)*unit, siz, !gs.fColor);
  384.     DrawColor(gi.kiLite);
  385.     DrawEdge(0, y*unit, unit, (y+1)*unit);
  386.     DrawEdge(y*unit, 0, (y+1)*unit, unit);
  387.     if (j <= cObj) for (x = 0, i = -1; x <= gs.nGridCell; x++) {
  388.       do {
  389.         i++;
  390.       } while (ignore[i] && i <= cObj);
  391.  
  392.       /* Again, we are looping through each cell in each row and column. */
  393.  
  394.       if (i <= cObj) {
  395.         gi.xTurtle = x*unit+unit/2;
  396.         gi.yTurtle = y*unit+unit/2 -
  397.           (gi.nScale/gi.nScaleT > 2 ? 5*gi.nScaleT : 0);
  398.         k = grid->n[i][j];
  399.  
  400.         /* If current cell is on top row or left hand column, draw glyph */
  401.         /* of planet owning the particular row or column in question.    */
  402.  
  403.         if (y == 0 || x == 0) {
  404.           if (x+y > 0)
  405.             DrawObject(j == 0 ? i : j, gi.xTurtle, gi.yTurtle);
  406.         } else {
  407.  
  408.         /* Otherwise, draw glyph of aspect in effect, or glyph of */
  409.         /* sign of midpoint, between the two planets in question. */
  410.  
  411.           if (gs.fAlt == us.fGridConfig) {
  412.             if (k) {
  413.               DrawColor(c = kAspB[k]);
  414.               DrawAspect(k, gi.xTurtle, gi.yTurtle);
  415.             }
  416.           } else {
  417.             DrawColor(c = kSignB(grid->n[i][j]));
  418.             DrawSign(grid->n[i][j], gi.xTurtle, gi.yTurtle);
  419.           }
  420.         }
  421.  
  422.         /* Again, when scale size is 300+, print some text in current cell: */
  423.  
  424.         if (gi.nScale/gi.nScaleT > 2 && gs.fLabel) {
  425.  
  426.           /* For top and left edges, print sign and degree of the planet. */
  427.  
  428.           if (y == 0 || x == 0) {
  429.             if (x+y > 0) {
  430.               k = SFromZ(y == 0 ? cp2.obj[i] : cp1.obj[j]);
  431.               l = (int)((y == 0 ? cp2.obj[i] : cp1.obj[j])-ZFromS(k));
  432.               c = kSignB(k);
  433.               sprintf(sz, "%c%c%c %02d", chSig3(k), l);
  434.  
  435.               /* For extreme upper left corner, print some little arrows */
  436.               /* pointing out chart1's planets and chart2's planets.     */
  437.  
  438.             } else {
  439.               c = gi.kiLite;
  440.               sprintf(sz, "1v 2->");
  441.             }
  442.           } else {
  443.             k = abs(grid->v[i][j]);
  444.  
  445.             /* For aspect cells, print the orb in degrees and minutes. */
  446.  
  447.             if (gs.fAlt == us.fGridConfig) {
  448.               if (grid->n[i][j])
  449.                 sprintf(sz, "%c%d %02d'", k != grid->v[i][j] ?
  450.                   (us.fAppSep ? 'a' : '-') : (us.fAppSep ? 's' : '+'),
  451.                   k/60, k%60);
  452.               else
  453.                 sprintf(sz, "");
  454.  
  455.             /* For midpoint cells, print degree and minute. */
  456.  
  457.             } else
  458.               sprintf(sz, "%2d %02d'", k/60, k%60);
  459.           }
  460.           DrawColor(c);
  461.           DrawSz(sz, x*unit+unit/2, (y+1)*unit-3*gi.nScaleT, dtBottom);
  462.         }
  463.       }
  464.     }
  465.   }
  466. }
  467.  
  468.  
  469. #ifdef BIORHYTHM
  470. /* Draw a graphic biorhythm chart on the screen, as is done when the -rb    */
  471. /* switch is combined with -X. This is technically a relationship chart in  */
  472. /* that biorhythm status is determined by a natal chart time at another     */
  473. /* later time. For the day in question, and for two weeks before and after, */
  474. /* the Physical, Emotional, and Mental percentages are plotted.             */
  475.  
  476. void XChartBiorhythm()
  477. {
  478.   char sz[6], *c;
  479.   real jd, r, a;
  480.   int x1, x2, xs, cx, y1, y2, ys, cy, i, j, k, x, y, x0, y0;
  481.  
  482.   k = xFont*6*gi.nScaleT;
  483.   x1 = k; x2 = gs.xWin-k; xs = x2-x1; cx = (x1+x2)/2;
  484.   k = CELLSIZE;
  485.   y1 = k; y2 = gs.yWin-k; ys = y2-y1; cy = (y1+y2)/2;
  486.  
  487.   /* Create a dotted day/percentage grid to graph on. */
  488.   DrawColor(gi.kiGray);
  489.   DrawDash(x1, cy, x2, cy, 1);
  490.   DrawDash(cx, y1, cx, y2, 1);
  491.   for (j = -BIODAYS+1; j <= BIODAYS-1; j++) {
  492.     x = x1 + NMultDiv(xs, j+BIODAYS, BIODAYS*2);
  493.     for (k = -90; k <= 90; k += 10) {
  494.       y = y1 + NMultDiv(ys, 100+k, 200);
  495.       DrawPoint(x, y);
  496.     }
  497.   }
  498.  
  499.   /* Now actually draw the three biorhythm curves. */
  500.   for (i = 1; i <= 3; i++) {
  501.     jd = RFloor(is.JD + rRound);
  502.     switch (i) {
  503.     case 1: r = brPhy; c = "PHYS"; j = eFir; break;
  504.     case 2: r = brEmo; c = "EMOT"; j = eWat; break;
  505.     case 3: r = brInt; c = "INTE"; j = eEar; break;
  506.     }
  507.     DrawColor(kElemB[j]);
  508.     for (jd -= (real)BIODAYS, j = -BIODAYS; j <= BIODAYS; j++, jd += 1.0) {
  509.       a = RBiorhythm(jd, r);
  510.       x = x1 + NMultDiv(xs, j+BIODAYS, BIODAYS*2);
  511.       y = y1 + (int)((real)ys * (100.0-a) / 200.0);
  512.       if (j > -BIODAYS)
  513.         DrawLine(x0, y0, x, y);
  514.       else
  515.         DrawSz(c, x1/2, y+2*gi.nScaleT, dtCent);
  516.       x0 = x; y0 = y;
  517.     }
  518.   }
  519.  
  520.   DrawColor(gi.kiLite);
  521.   /* Label biorhythm percentages along right vertical axis. */
  522.   for (k = -100; k <= 100; k += 10) {
  523.     sprintf(sz, "%c%3d%%", k < 0 ? '-' : '+', abs(k));
  524.     y = y1 + NMultDiv(ys, 100-k, 200);
  525.     DrawSz(sz, (x2+gs.xWin)/2, y+2*gi.nScaleT, dtCent);
  526.   }
  527.   /* Label days on top horizontal axis. */
  528.   for (j = -BIODAYS+2; j < BIODAYS; j += 2) {
  529.     x = x1 + NMultDiv(xs, j+BIODAYS, BIODAYS*2);
  530.     sprintf(sz, "%c%d", j < 0 ? '-' : '+', abs(j));
  531.     DrawSz(sz, x, y1-2*gi.nScaleT, dtBottom);
  532.   }
  533.   DrawEdge(x1, y1, x2, y2);
  534. }
  535. #endif /* BIORHYTHM */
  536. #endif /* GRAPH */
  537.  
  538. /* xcharts2.c */
  539.